<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2022/1/18
  Time: 14:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="common/head.jsp"%>
<html>
<head>
    <title>请假审核</title>
    <script src="../static/js/jquery-3.4.1.js"></script>
    <script>

    $(function (){

    $.ajax({
    url:"../leave/select",
    data:{},
    type:"post",
    dataType:"json",
    success:function(data){
       var str="";
        for (var i in data ){
            if (i ==0 ){
                str+="<option value='"+data[i].leaveid+"' selected>"+data[i].leaveid+"</option>"
            }else{
                str+="<option value='"+data[i].leaveid+"'>"+data[i].leaveid+"</option>"
            }
           }
        $(".absenceid").html(str)
        selectid(data[0].leaveid)
    }
    })
    })
    function reset1(){
        $(".dealresult").val("")
        var message = $(".status").val(1);
        alert(message)
    }
    function clazz1(clazz){
        var val = $(".dealperson").val();
        alert(val)
    $.ajax({
        url:"../user/lookclazz",
        data:{tname:val},
        type:"post",
        dataType:"json",
        success:function(data){
            alert(data.clazz)
            alert("sdjkas"+clazz)
            if (clazz == data.clazz){
                alert("true")
                $(".leaveperson").val(data[0].leaveperson)
                return true;
            }else {
                alert("false")
                $(".leaveperson").val("")
                $(".leavetime").val("")
                $(".starttime").val("")
                $(".leavereson").html("")
                return false;
            }



        }
    })


    }
    function selectid(absenceid){
        var val = $("select :selected").val();
        var b = false;
        alert(val)
        $.ajax({
            url:"../leave/select",
            data:{leaveid:val},
            type:"post",
            dataType:"json",
            success:function(data){
                $(".leaveperson").val(data[0].leaveperson)
                alert("leaveperson"+data[0].leaveperson)
                $.ajax({
                    url: "../user/lookstudent1",
                    data: {stuname: data[0].leaveperson},
                    type: "post",
                    dataType: "json",
                    success: function (data) {
                        // alert(data.stuname)
                        b = clazz1(data.clazz);
                            // alert(number1)
                                // if (data.clazzclazz1()){
                                //     alert("jdskfjsdf")
                                // }
                        // alert(number)
                    }
                })
                // var s = new Date()
                // var year = s.getFullYear();
                // var mon=s.getMonth()+1;
                // var date1 = s.getDate();
                // var mytime = year+"-"+mon+"-"+date1;
                // alert()
                    $(".leavetime").val(data[0].leavetime.substr(0,10))
                    $(".starttime").val(data[0].starttime.substr(0,10))
                    $(".leavereson").html(data[0].leavereson)




            } })
        $.ajax({
                url:"../leave/selectabsence",
                data:{absenceid:val},
                type:"post",
                dataType:"json",
                success:function(data){
                    if (data.length>0 && data[0].absenceid==val){
                        $('input[name="status"]:eq(1)').attr("checked",'checked');
                        alert(data[0].dealtime)
                        $(".dealtime").val(data[0].dealtime.substr(0,10))
                        $(".dealresult").val(data[0].dealresult)
                        $(".reset").attr("disabled")

                    }else {
                        $('input[name="status"]:eq(0)').attr("checked",'checked');
                        $(".dealtime").val("")
                        $(".dealresult").val("")
                        $(".dealtime").val("")
                    }
                }


                //

                // $(".dealperson").val()
                // $(".dealtime").val()
                // $(".dealresult").val()
                // var str="";
                //
                // for (var i in data ){
                //     str+="<option value='"+data[i].leaveid+"'>"+data[i].leaveid+"</option>"
                // }
                // $(".absenceid").html(str)
            }

        // var status = $(".status").val();

        )

    }
    function absenceForm() {
        var absence = $(".absenceForm").serializeArray();
        $.ajax({
            url:"../leave/insertabsence",
            data:absence,
            type:"post",
            dataType:"json",
            success:function(data){
            if (data == true){
                alert("添加成功")
            }else{
                alert("添加失败")
            }
            }
        })
        return false;

    }

    </script>
</head>
<style>
    table,form{
        margin-left: auto;
        margin-right: auto;
        margin-top: 20px;
    }
</style>
<body>
<%--240,248,255--%>
<form class="absenceForm" onsubmit="return absenceForm()"  >
    <table style="width: 800px;height: 250px;background-color: #f0f8ff;" border="1px solid red" cellspacing="0px"  >
        <caption><h2>请假审核</h2></caption>
        <tr >
            <td>编号：</td>
            <td>
                <select class="absenceid" name="absenceid" onchange="selectid()">
                    <option value=""></option>
                </select>
            <td>请假人：</td>
            <td><input class="leaveperson" required name="leaveperson" type="text"></td>
        </tr>
        <tr>
            <td>请假时间：</td>
            <td><input class="leavetime" required name="leavetime" type="date"></td>
            <td>开始时间：</td>
            <td><input  class="starttime" required name="starttime" type="date"></td>
        </tr>
        <tr>
            <td>请假原因：</td>
            <td colspan="3">
                <textarea class="leavereson" required name="leavereson" cols="70" rows="10"></textarea>
            </td>
        </tr>
        <tr>
            <td></td>
        </tr>
        <tr>
            <td>审核状态：</td>
            <td colspan="3">
                <div align="center">
                    <input type="radio"  required class="status" name="status" checked value="0">是
                    <input type="radio"  required class="status" name="status" value="1">否
                </div>
            </td>
        </tr>
        <tr >
            <td>处理时间：</td>
            <td><input name="dealtime" required class="dealtime" type="date"></td>
            <td>处理人：</td>
            <td><input name="dealperson" required class="dealperson" value="${userSession.username}" type="text"></td>
        </tr>
        <tr>
            <td>处理结果：</td>
            <td colspan="3"><textarea  required name="dealresult" class="dealresult" cols="70" rows="10"></textarea></td>
        </tr>
        <tr>
            <td colspan="4">
                <div align="center">
                <input type="submit" value="修改">
                <input type="button"  class="reset" onclick="reset1()" value="重置">
                </div>
            </td>
        </tr>
    </table>
</form>
<%@include file="common/foot.jsp" %>
</body>
</html>
